import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'

Vue.use(Router)

const ErrorPage = () => import('@/components/ErrorPage')
const login = () => import('@/components/login/login')
const PersonalCenter = () => import('@/components/PersonalCenter/index')
const ListenToHistory = () => import('@/components/PersonalCenter/PersonalMusic/ListenToHistory')
const MyCollection = () => import('@/components/PersonalCenter/PersonalMusic/MyCollection')
const MyDownloads = () => import('@/components/PersonalCenter/PersonalMusic/MyDownloads')
const MyConcerns = () => import('@/components/PersonalCenter/MyConcerns')
const MyComments = () => import('@/components/PersonalCenter/MyComments')
const BaskInTheSun = () => import('@/components/PersonalCenter/BaskInTheSun')

const setting = () => import('@/components/PersonalCenter/setting')
const PersonalSettings = () => import('@/components/PersonalCenter/setting/PersonalSettings')
const AccountSecurity = () => import('@/components/PersonalCenter/setting/AccountSecurity')
const NewNewsAlert = () => import('@/components/PersonalCenter/setting/NewNewsAlert')
const AboutAerobic = () => import('@/components/PersonalCenter/setting/AboutAerobic')
const businessCard = () => import('@/components/PersonalCenter/setting/businessCard')
const NotLoggedIn = () => import('@/components/PersonalCenter/NotLoggedIn')

const AudioSharing = () => import('@/components/AudioSharing/index')

const column = () => import('@/components/column/index')
const columnSearch = () => import('@/components/column/columnSearch')
const columnSearchList = () => import('@/components/column/columnSearchList')

const PopSlowSongs = () => import('@/components/PopSlowSongs/index')
const ExclusiveColumnList = () => import('@/components/ExclusiveColumnList/index')
const search = () => import('@/components/search/index')
const searchList = () => import('@/components/search/searchList')
const newSearch = () => import('@/components/search/search')

const Album = () => import('@/components/Album/index')
const albumDetail = () => import('@/components/Album/albumDetail')

const Talent = () => import('@/components/Talent/index')
const TalentOther = () => import('@/components/Talent/TalentOther')
const TalentSearch = ()=>import('@/components/Talent/TalentSearch')

const Playing = () => import('@/components/Playing/index')
// const Playing = () => import('@/components/Playing/test')

const Comment = () => import('@/components/Comment/index')
const commentDetail = () => import('@/components/Comment/commentDetail')



const Default = [{
    path: '/',
    name: 'index',
    component: index,
    meta: {
      title: '有氧FM'
    }
  }, 
  {
    path: '/NewSearch',
    name: 'NewSearch',
    component: newSearch,
    meta: {
      title: '个人中心',
      Auth:false
    }
  },{
    path: '/PersonalCenter',
    name: 'PersonalCenter',
    component: PersonalCenter,
    meta: {
      title: '个人中心',
      Auth:false
    }
  }, {
    path: '/setting',
    name: 'setting',
    component: setting,
    meta: {
      title: '设置'
    }
  }, {
    path: "/PersonalSettings",
    name: "PersonalSettings",
    component: PersonalSettings,
    meta: {
      title: '个人设置'
    }
  }, {
    path: "/AccountSecurity",
    name: "AccountSecurity",
    component: AccountSecurity,
    meta: {
      title: '账号与安全'
    }
  }, {
    path: "/NewNewsAlert",
    name: "NewNewsAlert",
    component: NewNewsAlert,
    meta: {
      title: '新消息提醒'
    }
  }, {
    path: "/AboutAerobic",
    name: "AboutAerobic",
    component: AboutAerobic,
    meta: {
      title: '关于有氧'
    }
  }, {
    path: "/ListenToHistory",
    name: "ListenToHistory",
    component: ListenToHistory,
    meta: {
      title: '收听历史'
    }
  }, {
    path: "/MyCollection",
    name: "MyCollection",
    component: MyCollection,
    meta: {
      title: '我的收藏'
    }
  }, {
    path: "/MyDownloads",
    name: "MyDownloads",
    component: MyDownloads,
    meta: {
      title: '我的下载'
    }
  }, {
    path: "/MyConcerns",
    name: "MyConcerns",
    component: MyConcerns,
    meta: {
      title: '我的关注'
    }
  }, {
    path: "/MyComments",
    name: "MyComments",
    component: MyComments,
    meta: {
      title: '我的评论'
    }
  }, {
    path: "/BaskInTheSun",
    name: "BaskInTheSun",
    component: BaskInTheSun,
    meta: {
      title: '晒一晒'
    }
  }, {
    path: "/businessCard",
    name: "businessCard",
    component: businessCard,
    meta: {
      title: '小程序名片'
    }
  }, {
    path: "/AudioSharing",
    name: "AudioSharing",
    component: AudioSharing,
    meta: {
      title: '音频分享'
    }
  }, {
    path: "/column",
    name: "column",
    component: column,
    meta: {
      title: '栏目列表'
    }
  },
  {
    path: "/columnSearch",
    name: "columnSearch",
    component: columnSearch,
    meta: {
      title: '栏目搜索'
    }
  },
  {
    path: "/columnSearchList",
    name: "columnSearchList",
    component: columnSearchList,
    meta: {
      title: '栏目搜索列表'
    }
  },
  {
    path: "/PopSlowSongs",
    name: "PopSlowSongs",
    component: PopSlowSongs,
    meta: {
      title: '流行慢歌'
    }
  }, {
    path: "/ExclusiveColumnList",
    name: "ExclusiveColumnList",
    component: ExclusiveColumnList,
    meta: {
      title: '专属栏目'
    }
  }, {
    path: "/search",
    name: "search",
    component: search,
    meta: {
      title: '搜索'
    }
  }, {
    path: "/searchList",
    name: "searchList",
    component: searchList,
    meta: {
      title: '搜索'
    }
  }, {
    path: "/Album",
    name: "Album",
    component: Album,
    meta: {
      title: '专题'
    }
  }, {
    path: "/albumDetail",
    name: "albumDetail",
    component: albumDetail,
    meta: {
      title: '专题详情'
    }
  }, {
    path: "/Talent",
    name: "Talent",
    component: Talent,
    meta: {
      title: '达人榜'
    }
  }, {
    path: "/TalentOther",
    name: "TalentOther",
    component: TalentOther,
    meta: {
      title: 'TA人主页'
    }
  },
  {
    path: "/TalentSearch",
    name: "TalentSearch",
    component: TalentSearch,
    meta: {
      title: '达人榜搜索'
    }
  },
   {
    path: "/Playing",
    name: "Playing",
    component: Playing,
    meta: {
      title: '正在播放'
    }
  }, {
    path: "/Comment",
    name: "Comment",
    component: Comment,
    meta: {
      title: '评论'
    }
  }, {
    path: "/commentDetail",
    name: "commentDetail",
    component: commentDetail,
    meta: {
      title: '评论详情'
    }
  },



]

const Login = [{
    path: '/login',
    name: 'login',
    component: login,
    meta: {
      title: '登录'
    }
  }, {
    path: '/NotLoggedIn',
    name: 'NotLoggedIn',
    component: NotLoggedIn,
    meta: {
      title: '未登录'
    }
  }

  //这里添加路由
  //meta配置:
  // Certificationstatus: 是否校验采购商认证
  // Auth: 是否需要验证登录
]

/**
 * 404
 */
const error = [{
  path: '*',
  name: '404',
  component: ErrorPage
}]

const routes = Default.concat(
  Login,
  error
);

const router = new Router({
  mode: 'history',
  base: '/',
  routes: routes,

})


//路由导航钩子
router.beforeResolve((to, from, next) => {
  let LoginAuth = to.meta.Auth || false;

  const token = Vue.prototype.$token;
  console.log('路由导航钩子',LoginAuth,token)
  //判断访问路由是否需要登录
  if (LoginAuth) {
    //判断是否登录
    if (token) {
      console.log('hasToken')
      next();
    } else {
      next({
        name: 'NotLoggedIn'
      })
    }
  } else {
    next();
  }
  //处理Title
  document.title = to.meta.title == undefined ? '有氧FM' : to.meta.title
  sugoio.load(to.fullPath,{})
  console.log(to.fullPath)
  const defaultBackground = '#FFF';
  // ScrollTop();
  /*处理Meta 背景设置*/
  /*     if (to.meta.backgroundColor) {
          document.getElementsByTagName('body')[0].style.background = to.meta.backgroundColor
      } else {
          document.getElementsByTagName('body')[0].style.background = defaultBackground;
      } */

})

//回滚顶部
const ScrollTop = () => {
  document.body.scrollTop = document.documentElement.scrollTop = 0;
}

export default router
